<?php
defined('PATH') or exit('Access Denied');
abstract class Model{
	public $db;
	/**
	 * 模块构造函数
	 */
	function __construct(){
		//执行初始化方法 
		$this->init();
	}
	/**
	 * 抽象一个模块初始化方法
	 */
	abstract function init();
	
	/**
	 * 打开数据连接
	 */
	function OpenDB(){
		$db_type=C('DB_TYPE');
		if (empty($db_type))$db_type='mysql';
		$dbtype="db_".$db_type;
		$dbhost=C('DBHOST');
		$dbuser=C('DBUSER');
		$dbpass=C('DBPASS');
		$dbname=C('DBNAME');
		$CACHE_CONF=C('CACHE');
		//$this->db=new $dbtype();
		$this->db=new db_mysqli();//开发中使用
		$this->db->pre=C('DBPRE');
		if ($db_type=='mssql' || $db_type=='access'){
			$this->db->connect($dbhost,$dbuser,$dbpass,$dbname);
		}else{
			$this->db->cache_type=$CACHE_CONF['cache_type'];
			$this->db->mem_host=$CACHE_CONF['mem_host'];
			$this->db->mem_port=$CACHE_CONF['mem_port'];
			$this->db->connect($dbhost,$dbuser,$dbpass,$dbname,$CACHE_CONF['cache_time'], 'UTF8');
		}
	}
}